package com.tonghe.controller;

import com.tonghe.annotation.SystemLog;
import com.tonghe.constants.SystemConstants;
import com.tonghe.domain.ResponseResult;
import com.tonghe.domain.dto.AddCommentDTO;
import com.tonghe.domain.entity.Comment;
import com.tonghe.service.CommentService;
import com.tonghe.utils.BeanCopyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Date:2022/3/11- 03- 11- 19:54
 * @author: tonghe
 **/
@RestController
@RequestMapping("/comment")
@Api(tags = "评论")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
    * @description: 添加评论
    * @author: TongHe
    * @date: 2022/8/20 16:40
    */
    @SystemLog(businessName = "添加评论")
    @PostMapping
    public ResponseResult addComment(@RequestBody AddCommentDTO addCommentDto){
        Comment comment = BeanCopyUtils.copyBean(addCommentDto, Comment.class);
        return commentService.addComment(comment);
    }

    // 文章评论
    /**
    * @description:
    * @param： [articleId, pageNum, pageSize]
    * @return： com.tonghe.domain.ResponseResult
    */
    @SystemLog(businessName = "文章评论列表")
    @GetMapping("/commentList")
    public ResponseResult commentList(Long articleId,Integer pageNum,Integer pageSize){

        return commentService.commentList(SystemConstants.ARTICLE_COMMENT,articleId,pageNum,pageSize);
    }

    @ApiOperation(value = "友链评论列表", notes = "获取一页友链评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页号"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小")
     })
    @SystemLog(businessName = "友链评论列表")
    @GetMapping("/linkCommentList")
    public ResponseResult linkCommentList(Integer pageNum,Integer pageSize){
        return commentService.commentList(SystemConstants.LINK_COMMENT,null,pageNum,pageSize);
    }

    @SystemLog(businessName = "致敬评论列表")
    @GetMapping("/respectCommentList")
    public ResponseResult respectCommentList(Integer pageNum,Integer pageSize){
        return commentService.commentList(SystemConstants.RESPECT_COMMENT,null,pageNum,pageSize);
    }

}
